package com.kay;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kay.dao.UserMapper;
import com.kay.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * @Description:MyBatis整合PageHelp分页插件测试
 * @Author: Kay
 * @CreateDate: 2021/6/29$ 16:18$
 * @UpdateUser: Kay
 * @UpdateDate: 2021/6/29$ 16:18$
 */
public class PageHelpTest {
    @Test
    public void test() throws IOException {
        InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactory sessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        SqlSession sqlSession = sessionFactory.openSession();
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);
        List<User> userList = userMapper.findAllUserOrderList();
        sqlSession.close();
        if (userList != null) {
            for (User user1 : userList) {
                System.out.println(user1);
            }
        }
        PageInfo pageInfo = new PageInfo(userList);
        System.out.println(pageInfo.getPageSize());
    }
}
